package com.zjd.dao;

import com.zjd.domain.Category;
import com.zjd.domain.Route;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface RouteDao {
    @Results(id = "Route_Map",
    value = {
            @Result(column = "rid", property = "rid"),
            @Result(column = "rname", property = "rname"),
            @Result(column = "price", property = "price"),
            @Result(column = "routeIntroduce", property = "routeIntroduce"),
            @Result(column = "rflag", property = "rflag"),
            @Result(column = "rdate", property = "rdate"),
            @Result(column = "isThemeTour", property = "isThemeTour"),
            @Result(column = "num", property = "num"),
            @Result(column = "cid", property = "cid"),
            @Result(column = "rimage", property = "rimage"),
            @Result(column = "sid", property = "sid"),
            @Result(column = "sourceId", property = "sourceId"),
            @Result(column = "cid", property = "category", javaType = Category.class,
                    one = @One(
                            select = "com.zjd.dao.CategoryDao.selectCategoryByRouteId"
                    ))
    })
    @Select("SELECT * FROM tab_route")
    List<Route> selecAllRoute();

    @Delete("DELETE FROM tab_route WHERE rid = #{rid}")
    void delReoute(Route route);

    @Insert(" INSERT INTO `tab_route`(`rid`,`rname`,`price`,`routeIntroduce`,`rflag`,`rdate`,`num`,`cid`,`rimage`,`sid`,`sourceId`)" +
            " VALUES ( NULL,#{rname},#{price},#{routeIntroduce},'0',NULL,'0',#{cid},NULL,NULL,NULL)")
    void saveRoute(Route route);

    @ResultMap("Route_Map")
    @Select("SELECT * FROM tab_route WHERE rid = #{rid}")
    Route findRouteByid(Route route);

    @Update("UPDATE `tab_route` SET `rname`=#{rname},`price`=#{price},`routeIntroduce`=#{routeIntroduce},`cid`=#{cid} WHERE `rid`=#{rid}")
    void updateRoute(Route route);

}
